// 问诊咨询相关数据的仓库

import { defineStore } from 'pinia'
import { ref } from 'vue'

export interface ConsultData {
  consultFlag: number
  illnessDesc: string
  illnessTime: number // 1 一周内
  pictures: { id: string; url: string }[]
}

// 用户病情数据 将来存/将来重置
const initData: ConsultData = {
  consultFlag: 0, // 0 没有就诊过
  illnessDesc: '',
  illnessTime: 1, // 1 一周内
  pictures: [],
}

export const useConsultStore = defineStore(
  'consult',
  () => {
    // 定义一个数据
    const illnessInfo = ref<ConsultData>({ ...initData }) // 是否就诊  患病时间  照片 描述

    // 定义个更新数据的方法
    const setIllnessInfo = (obj: ConsultData) => {
      illnessInfo.value = obj
    }

    // 科室id
    const depId = ref('')
    const setDepId = (id: string) => {
      depId.value = id
    }

    // 三家/普通
    const illnessType = ref('')
    const setIllnessType = (type: string) => {
      illnessType.value = type
    }

    // 极速问诊/找医生/开药
    const type = ref('')
    const setType = (types: string) => {
      type.value = types
    }

    const patiendId = ref('')
    const setPatientId = (id: string) => {
      patiendId.value = id
    }

    const clear = () => {
      // 全部回复成初始
      illnessInfo.value = { ...initData } // 对象类型的数据是个引用  地址
      depId.value = ''
      type.value = ''
      illnessType.value = ''
      patiendId.value = ''
    }

    return {
      illnessInfo,
      setIllnessInfo,
      depId,
      setDepId,
      illnessType,
      setIllnessType,
      type,
      setType,
      patiendId,
      setPatientId,
      clear,
    } // 只要外部想用仓库数据  必须return
  },
  {
    unistorage: true, // 仓库数据持久化
  }
)
